package com.woldier.aop.demo02;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component //交给spring
@Aspect
@Slf4j
public class AdviceDemo02 {
    @Around("@annotation(com.woldier.aop.demo02.Task02Anno)")
    public Object around1(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("around1");
        Object proceed = joinPoint.proceed(); //得到调用后的返回,如果我们不将器返回出去,那么被代理的对象不会得到返回值
        log.info("around after");
        return proceed;

    }


    @Around("@annotation(com.woldier.aop.demo02.Task02Anno)")
    public Object around2(ProceedingJoinPoint joinPoint) throws Throwable {
        Signature signature = joinPoint.getSignature(); // 得到签名 我们可以通过签名来判断是哪一类函数,对不同函数加以不同的处理

        Object[] args = joinPoint.getArgs();
        for (int i = 0; i < args.length; i++) { //遍历参数
            args[i] = "aspect";
        }
        Object proceed = joinPoint.proceed(args); //得到调用后的返回,如果我们不将器返回出去,那么被代理的对象不会得到返回值

        return proceed;

    }
}
